package cn.ctodb.mall.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * A BackGoods.
 */
@Entity
@Table(name = "back_goods")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "backgoods")
public class BackGoods implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "goods_name")
    private String goodsName;

    @OneToOne
    @JoinColumn(unique = true)
    private DeliveryGoods deliveryGoods;

    @ManyToOne
    private BackOrder backOrder;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public BackGoods goodsName(String goodsName) {
        this.goodsName = goodsName;
        return this;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public DeliveryGoods getDeliveryGoods() {
        return deliveryGoods;
    }

    public BackGoods deliveryGoods(DeliveryGoods deliveryGoods) {
        this.deliveryGoods = deliveryGoods;
        return this;
    }

    public void setDeliveryGoods(DeliveryGoods deliveryGoods) {
        this.deliveryGoods = deliveryGoods;
    }

    public BackOrder getBackOrder() {
        return backOrder;
    }

    public BackGoods backOrder(BackOrder backOrder) {
        this.backOrder = backOrder;
        return this;
    }

    public void setBackOrder(BackOrder backOrder) {
        this.backOrder = backOrder;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        BackGoods backGoods = (BackGoods) o;
        if (backGoods.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, backGoods.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "BackGoods{" +
            "id=" + id +
            ", goodsName='" + goodsName + "'" +
            '}';
    }
}
